//
//  IdentifyAndMaintainViewController.m
//  Luxury
//
//  Created by DCQ on 2018/5/21.
//  Copyright © 2018年 ZNXZ. All rights reserved.
//

#import "IdentifyAndMaintainViewController.h"
#import "IdAndMaOrderListViewController.h"
#import "LLSegmentBar.h"
#import "LLSegmentBarConfig.h"
@interface IdentifyAndMaintainViewController ()<LLSegmentBarDelegate>
@property(nonatomic, assign) ViewStyle  viewStyle;
@property (nonatomic,strong) LLSegmentBar * segmentBar;
@end

@implementation IdentifyAndMaintainViewController
- (instancetype)initWithStyle:(ViewStyle) style{
    self = [super init];
    if (self) {
        self.viewStyle = style;
    }
    return self;
}

- (LLSegmentBar *)segmentBar{
    if (!_segmentBar) {
        LLSegmentBar *segmentBar = [LLSegmentBar segmentBarWithFrame:self.view.bounds];
        segmentBar.delegate = self;
   
        [self.view addSubview:segmentBar];
        _segmentBar = segmentBar;
    }
    return _segmentBar;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupNavigationBar];
    [self setupXLTabIndicator];
 
}
- (void)setupNavigationBar{
    // 1 设置segmentBar的frame
    self.segmentBar.frame = CGRectMake(100, 0, [UIScreen mainScreen].bounds.size.width -200, 35);
    NSArray *items = @[@"鉴定", @"养护"];
    self.segmentBar.items = items;
    self.navigationItem.titleView = self.segmentBar;
    [self.segmentBar updateWithConfig:^(LLSegmentBarConfig *config) {
        config.itemNormalColor(UIColorFromRGB(0x333333)).itemSelectColor(UIColorFromRGB(0xAD9B6A)).indicatorColor(UIColorFromRGB(0xAD9B6A)).indicatorExtraW(-10).segmentBarBackColor([UIColor clearColor]);
        
    }];
    if (self.viewStyle == ViewStyle_Identify) {
       self.segmentBar.selectIndex = 0;
    }else if (self.viewStyle == ViewStyle_Maintain){
       self.segmentBar.selectIndex = 1;
        
    }

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)setupXLTabIndicator{
    
    self.buttonBarView.shouldCellsFillAvailableWidth = YES;
    self.isProgressiveIndicator = YES;
    self.isElasticIndicatorLimit = YES;
    self.buttonBarView.selectedBarAlignment = XLSelectedBarAlignmentCenter;
    self.buttonBarView.selectedBar.backgroundColor =  UIColorFromRGB(0xAD9B6A);
    self.buttonBarView.isAutoIndicatorWidth = NO;
    self.buttonBarView.indicatorWidth = 20;

    self.buttonBarView.backgroundColor = [UIColor whiteColor];
    self.bottomLineView.backgroundColor =  UIColorFromRGB(0xECEEEE);
    self.buttonBarView.bottomLineHeight = 1;
    
}
-(NSArray *)childViewControllersForPagerTabStripViewController:(XLPagerTabStripViewController *)pagerTabStripViewController{
    OrderVCType  vcType =  OrderVCType_normal;
    if (self.viewStyle == ViewStyle_Identify) {
        vcType = OrderVCType_identify;
    }else if (self.viewStyle == ViewStyle_Maintain){
        vcType = OrderVCType_maintain;
        
    }
    IdAndMaOrderListViewController * oneVC = [[IdAndMaOrderListViewController alloc]initWithStyle:TableViewControllerStyle_all withType: vcType];
    IdAndMaOrderListViewController * twoVC = [[IdAndMaOrderListViewController alloc]initWithStyle:TableViewControllerStyle_waitPayment withType: vcType];
    IdAndMaOrderListViewController * threeVC = [[IdAndMaOrderListViewController alloc]initWithStyle:TableViewControllerStyle_waitSend withType: vcType];
    IdAndMaOrderListViewController * IdentifyVC = [[IdAndMaOrderListViewController alloc]initWithStyle:TableViewControllerStyle_waitIdentify withType: vcType];
    IdAndMaOrderListViewController * fiveVC = [[IdAndMaOrderListViewController alloc]initWithStyle:TableViewControllerStyle_waitComments withType: vcType];
    
    IdAndMaOrderListViewController * maintainVC = [[IdAndMaOrderListViewController alloc]initWithStyle:TableViewControllerStyle_waitMaintain withType: vcType];
    IdAndMaOrderListViewController * waitGoodsVC = [[IdAndMaOrderListViewController alloc]initWithStyle:TableViewControllerStyle_waitGoods withType: vcType];
    NSArray * childViewControllers = @[];
    if (self.viewStyle == ViewStyle_Identify) {
        childViewControllers = [NSMutableArray arrayWithObjects:oneVC,twoVC,threeVC,waitGoodsVC,IdentifyVC,fiveVC,nil];
    }else if(self.viewStyle == ViewStyle_Maintain){
         childViewControllers = [NSMutableArray arrayWithObjects:oneVC,twoVC,threeVC,waitGoodsVC,maintainVC,fiveVC,nil];
    }
  
    return childViewControllers;
}

- (void)segmentBar:(LLSegmentBar *)segmentBar didSelectIndex:(NSInteger)toIndex fromIndex:(NSInteger)fromIndex{
     self.currentIndex = 0;
    if (toIndex == 0) {
        self.viewStyle = ViewStyle_Identify;
    }else if(toIndex == 1){
        self.viewStyle = ViewStyle_Maintain;
        
    }
    
    [self reloadPagerTabStripView];
}

- (UIColor *)getTabTitleColorSelected{
    
    return UIColorFromRGB(0xAD9B6A);
}
- (UIColor *)getTabTitleColorNor{
    return  UIColorFromRGB(0x333333);
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
